# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
require 'recaptcha'

class ApplicationController < ActionController::Base
  include LoginSystem
  include ReCaptcha::AppHelper
  # Pick a unique cookie name to distinguish our session data from others'
  session :session_key => '_src_session_id'
  
  def logined
    return !User.find_by_id(session[:user_id]).nil?
  end
  
  def owner_authorized?
    return current_user && current_lough && current_user.owns?(current_lough)
  end
  
  def current_user
    @current_user = session[:user_id] && User.find_by_id(session[:user_id])
  end
  
  def current_lough
    @current_lough = Lough.find_by_screen_name(params[:screen_name])
  end
  
  protected
    
  def check_current_lough
    if current_lough
      return true
    end
    
    return_to_welcome
  end
  
  def return_to_welcome
    redirect_to welcome_url
  end
  
end
